<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<script>
	var form_url = $.webapp.root + "/admin/site/magic/add.do" ; 
	$(function() {
		form_url = $.webapp.root + "/admin/site/magic/update.do" ;
		$.post($.webapp.root + "/admin/site/magic/get.do", {id:$('input[name=id]').val()}, function(result) {
			if (result.id != undefined) {
				$("#magicView").html("<img src='"+result.path+"'>") ;
				$('#form').form('load', result);
			}
		}, 'json').error(function(){$.easyui.loaded();});
		
		$("#import_user_data").euploadify({
			required: false, border: false, fileTypeExts : '*.jpg; *.png',
		 	swf: $.webapp.root+'/script/plugins/uploadify/uploadify.swf',
		 	uploader: $.webapp.root+'/fileAction/doNotNeedAuth_Upload.do',
	        onUploadSuccess: function(file, data, response) {
	        	filedata = $.parseJSON(data) ;
	        	$("input[name=path]").val(filedata.web_url) ;
	        	
	    		$("#magicView").html("<img src='"+filedata.web_url+"'>") ;
	        }
		});
	});
	
	//提交表单数据
	var submitNow = function($d, $tg, flag) {
		$.post(form_url, $("#form").form("getData"), function(result) {
			if (result.status) {
				$tg.treegrid("reload");$.easyui.loaded(); 
				alertify.success(result.msg);
				if(flag==undefined||flag==false){$d.dialog("close") ;}
			} else {
				$.easyui.loaded();$.messager.alert("错误", result.msg, "error");
			}
		}, 'json').error(function(){$.easyui.loaded();});
	};
	
	//验证表单
	var submitForm = function($d, $tg, flag) {
		if($('#form').form('validate')) {
			$.easyui.loading({ msg: "数据提交中，请稍等..." });
			submitNow($d, $tg, flag) ;
		} 
	};
</script>

<form id="form" class="easyui-form form_container">
	<input type="hidden" name="id" value="${id}" />
	<input type="hidden" name="pid" />
	<input type="hidden" name="isCategory" value="false" />
	<table class="tableform">
		<tr>
			<th>名称：</th>
			<td><input name="name" class="easyui-validatebox" data-options="required: true" type="text" /></td>
		</tr>
		<tr>
			<th style="width: 90px;">描述：</th>
			<td> 
				<textarea name="remark" class="easyui-validatebox" data-options="required: true" rows="5" cols="5" style="width:97%; height:80px;border:1px solid #ccc; overflow: auto;"></textarea>
			</td>
		</tr>
		<tr>
			<th>上传图片：</th>
			<td>
				<input name="path" type="hidden" />
				<div id="import_user_data" data-options="required: false" style="border:1px solid red;"></div>
			</td>
		</tr>
		<tr>
			<td colspan="2">
				<div id="magicView"></div> 
			</td>
		</tr>
	</table>
</form>